package cn.chint.manage.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.chint.bo.MsgEnterPages;
import cn.chint.bo.MsgEnterTempbo;
import cn.chint.bo.OrderOperatePages;
import cn.chint.bo.Ordersbo;
import cn.chint.manage.dao.MsgenterDao;
import cn.chint.manage.dao.OrderOperateDao;
import cn.chint.util.UtilDate;
@Controller
public class OrderOperateController {
	@Autowired
	OrderOperateDao OrderOperateDao ;
	public Logger log = Logger.getLogger(getClass());
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value = "order_list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public Map find_orderlist(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException {

		
		String page = request.getParameter("page");
		String size = request.getParameter("size");
		log.info(page);
		log.info(size);

		OrderOperatePages orderoperatepages =OrderOperateDao.find_orderlist(Integer.parseInt(page),Integer.parseInt(size));

		List<Ordersbo>  ls  = orderoperatepages.getLs();
		
		// JSONArray json =JSONArray.fromObject(list);
		@SuppressWarnings("rawtypes")
		Map<String, Object> r = new HashMap();
		r.put("code", 0);
		r.put("msg", "");
		r.put("count", orderoperatepages.getOrder_num());
		r.put("total_amount", orderoperatepages.getTotal_amount());
		r.put("find_amount", orderoperatepages.getTotal_amount());
		r.put("data", ls);
		return r ;
	}
	
	//后台模糊查询
		@SuppressWarnings({ "unchecked", "rawtypes" })
		@RequestMapping(value = "find_order_by_name", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
		@ResponseBody
		public Map  find_order_by_name(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException {
			String nickname=request.getParameter("nickname");
			String startTime=request.getParameter("startTime");
			String endTime=request.getParameter("endTime");
			String page = request.getParameter("page");
			String size = request.getParameter("size");
			log.info(startTime);
			log.info(endTime);
			log.info(nickname);
			OrderOperatePages orderoperatepages =OrderOperateDao.find_order_by_name(Integer.parseInt(page),Integer.parseInt(size),nickname,startTime,endTime);

			List<Ordersbo>  ls  = orderoperatepages.getLs();

			@SuppressWarnings("rawtypes")
			Map<String, Object> r = new HashMap();
			r.put("code", 0);
			r.put("msg", "");
			r.put("count", orderoperatepages.getOrder_num());
			r.put("total_amount", orderoperatepages.getTotal_amount());
			r.put("find_amount", orderoperatepages.getFind_amount());
			r.put("data", ls);

			return r ;
		}
}
